package com.xiaochong.bitong.api.controller;

import com.xiaochong.bitong.api.constant.HttpHeaderCons;
import com.xiaochong.bitong.api.service.SelfSelectService;
import com.xiaochong.bitong.api.utils.ApiVersion;
import com.xiaochong.bitong.api.utils.RequestUtil;
import com.xiaochong.tir.common.data.mapperSearchResult.ExchangeTransactionpair;
import com.xiaochong.tir.common.data.po.SelfSelected;
import com.xiaochong.tir.common.data.vo.ApiResultVo;
import com.xiaochong.tir.common.data.vo.app.AppSelfSelectCoinPairVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Description: 自选
 * @Author: org
 * @CreateDate: 2018/8/15 17:49
 */
@Api(value="自选T2.1接口")
@RestController
@RequestMapping(ApiVersion.API_V1_PREFIX+"/ShelSelect")
public class ShelSelectController {

    @Autowired
    private SelfSelectService selfSelectService;

    @ApiOperation(value = "自选取消或加入自选", notes = "返回code：00000-成功；")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "1、为自选交易对；2、为自选货币", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "unique_annotation", value = "如果type为1，则为交易所交易对中间表id；如果type为2，则为货币表id", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "flagType", value = "1、插入；2、删除(非编辑页面，无自选di时使用此方法);", required = true, dataType = "int", paramType = "query")
    })
    @PostMapping("/joinAndCancelShelSelect"+HttpHeaderCons.AUTH_URL)
    public ApiResultVo joinAndCancelShelSelect(@RequestParam(value = "flagType") Integer flagType, @RequestParam(value = "type") Integer type,
                                               @RequestParam(value = "unique_annotation") Integer unique_annotation,
                                               HttpServletRequest request){
        String token = RequestUtil.getHeaderName(request  , HttpHeaderCons.TOKEN);
        return selfSelectService.joinAndCancelShelSelect(type,token,unique_annotation,flagType);
    }
    @ApiOperation(value = "自选批量删除", notes = "返回code：00000-成功；")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "SelectIds", value = "selectId组装成字符串用英文分号结尾：1,2,", required = true, dataType = "String", paramType = "query")
    })
    @PostMapping("/deleteShelSelectBatch"+HttpHeaderCons.AUTH_URL)
    public ApiResultVo deleteShelSelectBatch(@RequestParam(value = "SelectIds") String SelectIds,
                                               HttpServletRequest request){
        String token = RequestUtil.getHeaderName(request  , HttpHeaderCons.TOKEN);
        return selfSelectService.deleteShelSelectBatch(token,SelectIds);
    }
    @ApiOperation(value = "取消自选（编辑页面，传入id）", notes = "返回code：00000-成功；")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "selectId", value = "自选id", required = true, dataType = "int", paramType = "query"),
    })
    @PostMapping("/deleteShelSelect"+HttpHeaderCons.AUTH_URL)
    public ApiResultVo deleteShelSelect(@RequestParam(value = "selectId") Integer selectId,
                                               HttpServletRequest request){
        String token = RequestUtil.getHeaderName(request  , HttpHeaderCons.TOKEN);
        return selfSelectService.deleteShelSelect(selectId,token);
    }
    /*@ApiOperation(value = "置顶", notes = "返回code：00000-成功；")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "selectId", value = "1、为自选交易对；2、为自选货币", required = true, dataType = "int", paramType = "query")
    })
    @PostMapping("/updateShelSelect"+HttpHeaderCons.AUTH_URL)
    public ApiResultVo updateShelSelect(@RequestParam(value = "selectId") Integer selectId,
                                               HttpServletRequest request){
        String token = RequestUtil.getHeaderName(request  , HttpHeaderCons.TOKEN);
        return selfSelectService.updateShelSelect(selectId,token);
    }*/
    @ApiOperation(value = "编辑顺序", notes = "返回code：00000-成功；")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sort", value = "顺序编辑页面自选货币或者交易对的列表id排成字符串例：1,2,3,", required = true, dataType = "String", paramType = "query")
    })
    @PostMapping("/updateSelfSelectSort"+HttpHeaderCons.AUTH_URL)
    public ApiResultVo updateSelfSelectSort(@RequestParam(value = "sort") String sort,
                                        HttpServletRequest request){
        String token = RequestUtil.getHeaderName(request  , HttpHeaderCons.TOKEN);
        return selfSelectService.updateSelfSelectSort(sort,token);
    }
    @ApiOperation(value = "自选列表" , notes = "自选列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sortField", value = "排序字段涨幅传change24hDouble和价格传priceCnyDouble排序", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "sortType", value = "desc或者asc（默认降序）", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "token", value = "用户token", required = false, dataType = "String", paramType = "query")
    })
    @PostMapping("coinPairMarketList")
    public ApiResultVo<List<AppSelfSelectCoinPairVo>> coinPairMarketList(
                                                              @RequestParam(value = "token", required = false) String token,
                                                              @RequestParam(value = "sortField", required = false) String sortField,
                                                              @RequestParam(value = "sortType", required = false) String sortType){
        ApiResultVo api=selfSelectService.coinPairMarketList(0,0,token,sortField,sortType);
        return api;
    }
    /*@ApiOperation(value = "自选列表（编辑页面）" , notes = "自选列表（编辑页面）")
    @PostMapping("coinPairNoMarketList")
    public ApiResultVo<List<SelfSelected>> coinPairNoMarketList(HttpServletRequest request){
        String token = RequestUtil.getHeaderName(request  , HttpHeaderCons.TOKEN);
        ApiResultVo api=selfSelectService.coinPairNoMarketList(token);
        return api;
    }*/
}
